
/*-----------------------------------------------------------------------------------
Name: Hyuk Son
Date: Aug 21 2020
This do file does : 
	setting up directories and packages
-----------------------------------------------------------------------------------*/
set more off
clear all

 *** log file 
cap mkdir "$log_path"

	local c_date = c(current_date)
	local cdate = subinstr("`c_date'", " ", "_", .)
	local c_time = c(current_time)
	local ctime = subinstr("`c_time'", ":", "_", .)

	log using "$log_path/logfile_`cdate'-`ctime'.log", replace text
 */

*** Program environment 
local variant = cond(c(MP),"MP",cond(c(SE),"SE",c(flavor)) )  

	di "=== SYSTEM DIAGNOSTICS ==="
	di "Stata version: `c(stata_version)'"
	di "Updated as of: `c(born_date)'"
	di "Variant:       `variant'"
	di "Processors:    `c(processors)'"
	di "OS:            `c(os)' `c(osdtl)'"
	di "Machine type:  `c(machine_type)'"
	di "=========================="

/* install any packages locally */
capture mkdir "$cdir/ado"
sysdir set PERSONAL "$cdir/ado/personal"
sysdir set PLUS     "$cdir/ado/plus"
sysdir set SITE     "$cdir/ado/site"
sysdir


*** Add required packages from SSC to this list 
    local ssc_packages "estout coefplot"
    
    if !missing("`ssc_packages'") {
        foreach pkg in `ssc_packages' {
            dis "Installing `pkg'"
			capture which `pkg'
			loc result _rc
			if `result'==111 ssc install `pkg', replace
        }
    }

    local net_packages " "
    
    if !missing("`net_packages'") {
        foreach pkg in `net_packages' {
            dis "Installing `pkg'"
			capture which `pkg'
			loc result _rc
			if `result'==111 net install `pkg', replace 
        }
    }
